﻿namespace Commander.Core.Services.Instantiations
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    class InstantiationKey
    {
        public Type ServiceType { get; private set; }

        public object Context { get; private set; }

        public bool IsGenericService { get { return ServiceType.IsGenericTypeDefinition; } }

        public InstantiationKey(Type type, object context)
        {
            ServiceType = type;
            Context = context;
        }

        public override int GetHashCode()
        {
            return ServiceType.GetHashCode() ^ (Context != null ? Context.GetHashCode() : 1);
        }

        public override bool Equals(object obj)
        {            
            InstantiationKey other = obj as InstantiationKey;

            if (other == null) return false;

            return GetHashCode() == other.GetHashCode();
        }
    }
}
